package com.epro.dx.activity.order;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.epro.dx.R;
import com.epro.dx.activity.BaseFragmentActivity;
import com.epro.dx.activity.CancelOrderActivity;
import com.epro.dx.activity.CheckoutActivity;
import com.epro.dx.activity.DetailActivity;
import com.epro.dx.activity.HomeActivity;
import com.epro.dx.activity.creditcard.AddCreditCardActivity;
import com.epro.dx.activity.creditcard.CreditCardListActivity;
import com.epro.dx.adapter.OrderProductAdapter;
import com.epro.dx.adapter.StatusTrackingAdapter;
import com.epro.dx.listenner.GetCreditCardInfoListenner;
import com.epro.dx.listenner.PaymentMethodDialogOnClickListenner;
import com.epro.dx.task.BaseNeedReLoginTask;
import com.epro.dx.util.ActivityUtil;
import com.epro.dx.util.AsyncTaskUtil;
import com.epro.dx.util.GetCreditCardInfoAsyncTask;
import com.epro.dx.util.PaymentMethodDialogUtils;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.HitBuilders.EventBuilder;
import com.google.android.gms.analytics.Tracker;
import com.weipu.common.DXApplication;
import com.weipu.common.DXApplication.TrackerName;
import com.weipu.common.constants.Constant;
import com.weipu.common.constants.ServerConstant;
import com.weipu.common.facade.exception.DxException;
import com.weipu.common.facade.factory.ProviderFactory;
import com.weipu.common.facade.model.CountryModel;
import com.weipu.common.facade.model.CreditCardInfo;
import com.weipu.common.facade.model.Operator;
import com.weipu.common.facade.model.OrderModel;
import com.weipu.common.facade.model.OrderModel.Liness;
import com.weipu.common.facade.model.OrderhistoryModel;
import com.weipu.common.facade.model.SimpleCreditCard;
import com.weipu.common.util.AlertToast;
import com.weipu.common.util.GlobalConfig;
import com.weipu.common.util.Logger;
import com.weipu.common.util.OnClickUtil;

/**
 * 订单详情
 * 
 * @author qsc255
 * @version [版本号, 2015-1-30]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class OrderDetailActivity extends BaseFragmentActivity implements
		OnClickListener {

	private static final String TAG = OrderDetailActivity.class.getSimpleName();

	/**
	 * 订单号
	 */
	private String orderNumber;

	/**
	 * 用户名
	 */
	private String userName;

	/**
	 * 订单对象
	 */
	private OrderModel orderModel;

	/**
	 * 订单历史状态
	 */
	private List<OrderhistoryModel> orderhistoryModel;

	/**
	 * 获取国家吗
	 */
	private CountryModel countryModel;

	/**
	 * 运送方式
	 */
	// Map<String, String> mapShippMethod;

	private boolean refreshAll = true;

	private boolean refreshHistory;

	// private TextView tvOrderReceived;
	//
	// private TextView tvPaymentReceived;
	//
	// private TextView tvFullShipment;
	//
	// private TextView tvCompleted;

	DateFormat format = new SimpleDateFormat("yyyy/M/d HH:mm");

	DateFormat format1 = new SimpleDateFormat("MM/dd/yyyy HH:mm");

	/**
	 * 订单商品列表适配器
	 */
	private OrderProductAdapter orderProductAdapter;

	/**
	 * 订单历史记录适配器
	 */
	private StatusTrackingAdapter statusTrackingAdapter;

	private ListView order_detail_listview;

	private ListView order_tracking_listview;

	OrderInfoAsyncTask orderInfoAsyncTask;

	OrderHistoryAsyncTask orderHistoryAsyncTask;

	BeginEditOrderAsyncTask beginEditOrderAsyncTask;

	ConfirmReceptAsyncTask confirmReceptAsyncTask;

	private ScrollView scrollview;

	private AlertDialog dialog;

	// /**
	// * 状态跟踪图片
	// */
	// private ImageView order_detail_tracking01, order_detail_tracking02,
	// order_detail_tracking03, order_detail_tracking04;
	//
	// /**
	// * 状态跟踪时间
	// */
	// private TextView order_detail_date_01, order_detail_date_02,
	// order_detail_date_03, order_detail_date_04;

	/**
	 * 订单号
	 */
	private TextView order_on_number;

	private TextView orderStatus;

	/**
	 * 接受人
	 */
	private TextView order_shipping_recipient;

	/**
	 * 国家
	 */
	private TextView order_shipping_country;

	/**
	 * 城市
	 */
	private TextView order_shipping_city;

	/**
	 * 地址
	 */
	private TextView order_shipping_address;

	/**
	 * 邮编
	 */
	private TextView order_shipping_code;

	/**
	 * 电话
	 */
	private TextView order_shipping_tel;

	/**
	 * 送货方式
	 */
	private TextView order_shipping_method;

	/**
	 * 折扣
	 */
	private TextView orderDiscount;

	private TextView orderDiscountTotal;

	/**
	 * 邮费总计
	 */
	private TextView shipping_total;
	/**
	 * 邮费折扣
	 */
	private TextView shipping_discount_total;
	private TextView shipping_discount;

	/**
	 * 订单总金额
	 */
	private TextView grandTotal;

	/**
	 * 部分支付需支付金额
	 */
	private TextView dueAmountTotal;

	/**
	 * 部分支付需支付金额TV
	 */
	private TextView dueAmountTotalTV;

	/**
	 * 修改订单
	 */
	private Button oprationOrder;

	/**
	 * 取消订单
	 */
	private Button cancelorder;
	/**
	 * 查看物流信息
	 */
	private Button checkShipping;

	/**
	 * 底部按钮所在的背景布局
	 */
	private RelativeLayout rLayout;

	/**
	 * edit and cancel btn top line
	 */
	private View viewline;

	// /**
	// * 隐藏动画按钮
	// */
	// private CheckBox uporDwon;

	private List<Liness> products = new ArrayList<Liness>();

	private boolean isPay = true;

	private Tracker tracker;

	private EventBuilder eventBuilder;
	
	private String fromActivity;
	
	// 复制板
	private ClipboardManager clipBoardManager;

	private TextView scTv;

    private View scdiv;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//添加GA跟踪代码
		tracker = DXApplication.getContext().getTracker(TrackerName.APP_TRACKER);
		tracker.setScreenName(OrderDetailActivity.class.getSimpleName());
		tracker.send(new HitBuilders.ScreenViewBuilder().build());
		eventBuilder = new HitBuilders.EventBuilder().setCategory("Click Button");
		// 不显示标题
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// 获取订单号
		boolean isGetDataOk = getExtrasData(savedInstanceState);
		if (!isGetDataOk) {
			finish();
			return;
		}
		setContentView(R.layout.activity_order_detail);
		setTitleContent(R.string.title_orderdetail);
		setLeftBtnContent(true, -1);
		initView();
		setListener();
		updateOrder();
	}

	private boolean getExtrasData(Bundle outSave) {
		Intent intent = getIntent();
		Bundle bundle = null;
		if (null != intent) {
			bundle = getIntent().getExtras();
		}
		if (null == bundle) {
			bundle = outSave;
		}
		if (null == bundle) {
			return false;
		}else{
//			Log.i("save", bundle.toString());
		}
		orderNumber = bundle.getString("OrderNumber");
		fromActivity=bundle.getString(ServerConstant.Parameter.PARAMETER_NAME_FROM_ACTIVITY);
		return true;
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		outState.putString("OrderNumber", orderNumber);
		outState.putString(ServerConstant.Parameter.PARAMETER_NAME_FROM_ACTIVITY, fromActivity);
		super.onSaveInstanceState(outState);
	}

	/**
	 * 初始化相关
	 */
	private void initView() {
		scrollview = (ScrollView) findViewById(R.id.scrollview);
		order_on_number = (TextView) findViewById(R.id.order_id_text);
		orderStatus = (TextView) findViewById(R.id.order_status);
		// 订单状态列表
		order_tracking_listview = (ListView) findViewById(R.id.status_tracking_list);

		// Produt 列表
		order_detail_listview = (ListView) findViewById(R.id.details_product_list);
		// 收件人详情
		order_shipping_recipient = (TextView) findViewById(R.id.order_shipping_recipitent_tv);
		order_shipping_country = (TextView) findViewById(R.id.order_shipping_country_tv);
		order_shipping_city = (TextView) findViewById(R.id.order_shipping_city_tv);
		order_shipping_address = (TextView) findViewById(R.id.order_shipping_address_tv);
		order_shipping_code = (TextView) findViewById(R.id.order_shipping_code_tv);
		order_shipping_tel = (TextView) findViewById(R.id.order_shipping_tel_tv);
		order_shipping_method = (TextView) findViewById(R.id.order_shipping_method_tv);
		// 商品订单总价格
		orderDiscountTotal = (TextView) findViewById(R.id.order_discount_total_text);
		orderDiscount = (TextView) findViewById(R.id.order_discount_total);
		grandTotal = (TextView) findViewById(R.id.order_grand_total);
		dueAmountTotal = (TextView) findViewById(R.id.order_due_amount);
		dueAmountTotalTV = (TextView) findViewById(R.id.order_due_amount_tv);
		// 邮费总计
		shipping_total = (TextView) findViewById(R.id.order_shipping_total);
		shipping_discount_total = (TextView) findViewById(R.id.order_shipping_discount_total);
		shipping_discount = (TextView) findViewById(R.id.order_shipping_discount);
		rLayout = (RelativeLayout) findViewById(R.id.order_btn_rl);
		viewline = findViewById(R.id.bottom_order_line);
		oprationOrder = (Button) findViewById(R.id.opration_order_btn);
		cancelorder = (Button) findViewById(R.id.cancel_order_btn);
		checkShipping = (Button) findViewById(R.id.check_shipping_btn);
		
		clipBoardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
		scTv = (TextView)findViewById(R.id.tv_order_sc);
		scdiv = findViewById(R.id.order_sc_div);
	}

	/**
	 * 监听事件
	 * 
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	@SuppressLint("NewApi")
	private void setListener() {
		// uporDwon.setOnClickListener(this);
		oprationOrder.setOnClickListener(this);
		cancelorder.setOnClickListener(this);
		checkShipping.setOnClickListener(this);
		// 商品列表item点击事件
		order_detail_listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// 点击商品列表时进入商品详情页面
				Intent intent = new Intent(OrderDetailActivity.this,
						DetailActivity.class);
				Bundle data = new Bundle();

				// data.putInt(ServerConstant.Parameter.PARAMETER_NAME_PRODUCT_ID,
				// orderModel.getLines().get(position).getSku());
				data.putInt(ServerConstant.Parameter.PARAMETER_NAME_PRODUCT_ID,
						products.get(position).getSku());

				data.putString(
						ServerConstant.Parameter.PARAMETER_NAME_BACK_ACTION,
						ServerConstant.ActionConstant.ACTION_ORDER_DETAIL);
				data.putString(
						ServerConstant.Parameter.PARAMETER_NAME_FROM_ACTIVITY,
						ServerConstant.ActionConstant.ACTION_ORDER_DETAIL);

				intent.putExtras(data);
				startActivity(intent);

			}
		});
		//订单号复制按钮
		findViewById(R.id.copy_order_number).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO 
				ClipData myClip = ClipData.newPlainText("text", order_on_number.getText().toString());
				clipBoardManager.setPrimaryClip(myClip);
				showToast(getString(R.string.copy_success));
			}
		});
	}

	/**
	 * 加载订单详情页面数据
	 * 
	 * @see [类、类#方法、类#成员]
	 */
	public void updateOrder() {

		if (refreshAll) {
			orderInfoAsyncTask = new OrderInfoAsyncTask();
			AsyncTaskUtil.executeTask(orderInfoAsyncTask);
		}
		// else if (refreshHistory)
		// {
		// orderHistoryAsyncTask = new OrderHistoryAsyncTask();
		// orderHistoryAsyncTask.execute();
		// }
	}

	/**
	 * 显示确认收获对话框
	 * 
	 */
	protected void showConfirmDialog() {

		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		View view = View.inflate(this, R.layout.dialog_confirm_receipt, null);

		ImageButton no = (ImageButton) view
				.findViewById(R.id.dialog_confirm_receipt_no);
		ImageButton yes = (ImageButton) view
				.findViewById(R.id.dialog_confirm_receipt_yes);

		// 按钮点击事件
		no.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 点击no按钮隐藏弹窗
				dialog.dismiss();

			}
		});
		yes.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
				AsyncTaskUtil.executeTask(new ConfirmReceptAsyncTask());
			}

		});
		builder.setView(view);
		dialog = builder.create();
		dialog.show();
	}
	
	/**
	 * 信用卡支付
	 */
	private void doCreditPay(){
		//信用卡支付需要先创建订单 然后获取信用卡列表信息
		AsyncTaskUtil.executeTask(new GetCreditCardInfoAsyncTask(new GetCreditCardInfoListenner() {
			
			@Override
			public void onPreGetInfo() {
				showLoadingLayout(null);
			}

			@Override
			public void onGetInfoFinish() {
				hideAllLayout(scrollview);
			}

			@Override
			public void onGetInfoComplect(
					CreditCardInfo creditCardInfo) {
				ArrayList<SimpleCreditCard> simpleCreditCards = (ArrayList<SimpleCreditCard>) creditCardInfo
						.getsCreditCards();
				Intent intent = new Intent();
				String type = creditCardInfo.getGatewayType();
				if (null == simpleCreditCards || simpleCreditCards.size() == 0) {
					intent.setClass(OrderDetailActivity.this, AddCreditCardActivity.class);
					intent.putExtra("fromPage", "toPay");
				} else {
					intent.setClass(OrderDetailActivity.this, CreditCardListActivity.class);
					intent.putExtra("CardFlow", type);
					intent.putParcelableArrayListExtra("CreditCards",
							simpleCreditCards);
				}
				intent.putExtra("CardFlow", type);
				intent.putExtra(ServerConstant.Parameter.PARAMETER_NAME_ORDER_NUMBER, orderNumber);
				startActivity(intent);
				
			}
			
		}, OrderDetailActivity.this,1));
	}

	/** 点击按钮的业务处理 */

	@Override
	public void onClick(View v) {
		if (OnClickUtil.isFastDoubleClick()) {
			return;
		}

		switch (v.getId()) {
		/**
		 * 修改订单
		 */
		case R.id.opration_order_btn:
			// beginEditOrderAsyncTask = new BeginEditOrderAsyncTask();
			// beginEditOrderAsyncTask.execute();
			// 目前暂时未定但编辑功能 先暂时调整为pay支付动作
//			Resources resource = getResources();
			// String opStr = oprationOrder.getText().toString();
			// if (resource.getString(R.string.title_pay_order).equals(opStr)) {
			if (isPay) {
				//添加GA跟踪
				tracker.send(eventBuilder.setAction("Pay").build());
				Logger.i(TAG, orderModel.getCurrencyCode());
				if (!"840".equals(orderModel.getCurrencyCode())) {
					Toast.makeText(
							OrderDetailActivity.this,
							getResources().getString(
									R.string.no_support_payment), 0).show();
					return;
				}
				if ("5".equals(orderModel.getLight())) {
					Toast.makeText(
							OrderDetailActivity.this,
							getResources().getString(
									R.string.no_support_partial_payment), 0)
							.show();
					return;
				}
				final boolean canRepay = orderModel.isCanRepay();
				if (!canRepay) {
					Toast.makeText(OrderDetailActivity.this,
							getResources().getString(R.string.can_not_pay), 0)
							.show();
					return;
				}
				int currentVersion = android.os.Build.VERSION.SDK_INT;
				if(14<=currentVersion&&currentVersion<19){
					//4.4以下版本不支持PayPal
					doCreditPay();
					return;
				}
				//支付方式选择
				PaymentMethodDialogUtils payMethodUtils=new PaymentMethodDialogUtils(new PaymentMethodDialogOnClickListenner() {
					
					@Override
					public void onPayPalClick() {
						payPalPayment(canRepay);
					}
					
					@Override
					public void onCreditCardClick() {
						doCreditPay();
					}
				});
				payMethodUtils.showChoosePaymentWindow(OrderDetailActivity.this);
				
			} else // if
					// (!isPay)//resource.getString(R.string.title_receipt_order).equals(opStr))
			{
				//添加GA跟踪
				tracker.send(eventBuilder.setAction("ConfirmRecept").build());
				showConfirmDialog();
			}

			break;
		/**
		 * 取消订单
		 */
		case R.id.cancel_order_btn:
			//添加GA跟踪
			tracker.send(eventBuilder.setAction("Cancel").build());
			Intent intent2 = new Intent(OrderDetailActivity.this,
					CancelOrderActivity.class);
			intent2.putExtra("orderNumber", orderNumber);
			intent2.putExtra("orderPrice",
					Constant.US_DOLLAR + orderModel.getGrandTotal());
			intent2.putExtra("orderStatus", orderModel.getOrderStatus());
			this.startActivityForResult(intent2,
					ServerConstant.Parameter.EDIT_REQUESTCODE);

			break;
		case R.id.check_shipping_btn:
			//跳转ShippingTracking
			Intent i = new Intent();
			i.setClass(getApplicationContext(), ShippingTrackingActivity.class);
			i.putExtra("OrderNumber", orderNumber);
			if(orderModel!=null){
				i.putExtra("CurrencyCode", orderModel.getCurrencyCodeStr());
			}
			startActivity(i);
			break;
		/**
		 * 动画隐藏订单状态
		 */
		// case R.id.order_upordown_btn:
		// findViewById(R.id.order_rl_status02).setVisibility(View.GONE);
		// findViewById(R.id.order_rl_status03).setVisibility(View.GONE);
		// findViewById(R.id.order_rl_status03).setVisibility(View.GONE);
		// break;
		//
		default:
			break;
		}
	}
	
	/**
	 * Paypal支付
	 * @param canRepay
	 */
	private void payPalPayment(boolean canRepay){
		Intent intent = new Intent(OrderDetailActivity.this,
				CheckoutActivity.class);
		boolean IsPaymentCompleted = orderModel.isIsPaymentCompleted();
		boolean isPartPay = false;
		if ("5".equals(orderModel.getLight()) && canRepay
				&& !IsPaymentCompleted) {
			isPartPay = true;
		}
		// 传递一个标识，表示从mycartActivity付款的，此时付款完成后需要删除购物车的商品
		intent.putExtra(
				ServerConstant.Parameter.PARAMETER_NAME_FROM_ACTIVITY,
				ServerConstant.ActionConstant.FORM_ORDERDETAIL_ACTIVITY);

		intent.putExtra("orderNumber", orderNumber);
		intent.putExtra("isPartPay", isPartPay);
		if (isPartPay) {
			intent.putExtra("DueAmount", orderModel.getDueAmount());
		}
		// startActivity(intent);
		startActivityForResult(intent,
				ServerConstant.Parameter.PAYMENT_RESULTCODE);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		Logger.d("OrderDetailActivity", "-----onActivityResult-----");
		Logger.d("TAG", "-----onActivityResult----- " + resultCode);
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == ServerConstant.Parameter.CANCEL_RESULTCODE
				|| resultCode == ServerConstant.Parameter.PAYMENT_RESULTCODE
				|| resultCode == ServerConstant.Parameter.EDIT_RESULTCODE) {

			refreshAll = true;
			Intent intent = new Intent();
			switch (resultCode) {
			case ServerConstant.Parameter.CANCEL_RESULTCODE:
				intent.putExtra("type", 0);
				break;
			case ServerConstant.Parameter.PAYMENT_RESULTCODE:
				intent.putExtra("type", 1);
				break;

			default:
				break;
			}

			OrderDetailActivity.this.setResult(
					ServerConstant.Parameter.ORDER_DETAILS_REQUESTCODE, intent);
			updateOrder();
		}
	}

	/**
	 * 加载订单详情信息
	 * 
	 * @author qsc255
	 * @version [版本号, 2015-2-3]
	 * @see [相关类/方法]
	 * @since [产品/模块版本]
	 */
	protected class OrderInfoAsyncTask extends BaseNeedReLoginTask {

		@Override
		protected void onPreExecute() {
			// showWaitingDialog();
			showLoadingLayout(null);
			oprationOrder.setVisibility(View.GONE);
			cancelorder.setVisibility(View.GONE);
		}

		@Override
		protected String doInBackground(Void... params) {
			try {
				orderModel = ProviderFactory.createOrderServiceProvider()
						.getOrder(orderNumber,ActivityUtil.getCustomerToken(),ActivityUtil.getCustomerID());
				if (null != BaseFragmentActivity.countryPreferences
						&& !BaseFragmentActivity.countryPreferences.getAll()
								.isEmpty()) {
					countryModel = new CountryModel();
					countryModel
							.setAllCountry(BaseFragmentActivity.countryPreferences
									.getAll());
				} else {
					// FIXME 该部分代码需要优化
					if (null == countryPreferences) {
						countryPreferences = getSharedPreferences(
								"countryData", MODE_PRIVATE);
					}
					countryModel = ProviderFactory.createUserServiceProvider()
							.allCountry();
					BaseFragmentActivity.persistenceCountry(countryModel
							.getAllCountry());
				}
				orderhistoryModel = ProviderFactory
						.createOrderServiceProvider().GetOrderStatusHistory(
								orderNumber,ActivityUtil.getCustomerToken(),ActivityUtil.getCustomerID());
				// mapShippMethod = new HashMap<String, String>();
				// mapShippMethod.put("0", "SuperSaver");
				// mapShippMethod.put("1", "Standard");
				// mapShippMethod.put("2", "Expedited");
			} catch (DxException e) {
				return e.getErrCode();
			} catch (Exception e) {
				Logger.e(TAG, "OrderInfoAsyncTask", e);
			}
			return "0";
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			if (!isFinishing()) {
				// oprationOrder.setVisibility(View.VISIBLE);
				// cancelorder.setVisibility(View.VISIBLE);
				Logger.d("---", "--" + result.toString());
				hideAllLayout(scrollview);
				if ("0".equals(result)) {
					hideAllLayout(scrollview);
					refreshHistory = false;
					refreshAll = false;
					setData();
					setHistory();
				} else if(!isRelogin){
					showErrorLayout(scrollview, R.string.internet_error,
							R.string.internet_suggest, R.drawable.no_internet);
					retryBtn.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							hideAllLayout();
							AsyncTaskUtil.executeTask(new OrderInfoAsyncTask());
						}
					});
					// AlertToast.alert(OrderDetailActivity.this,
					// ServerConstant.ReturnCode.MESSAGEMAP.get(result));
				}
			}

		}

		@Override
		protected Context setContext() {
			return OrderDetailActivity.this;
		}

		@Override
		protected BaseNeedReLoginTask setTask() {
			return new OrderInfoAsyncTask();
		}
	}

	/**
	 * 获取订单历史记录
	 * 
	 * @version [版本号, 2015-2-3]
	 * @see [相关类/方法]
	 * @since [产品/模块版本]
	 */
	protected class OrderHistoryAsyncTask extends BaseNeedReLoginTask {

		@Override
		protected void onPreExecute() {
			// showWaitingDialog();
		}

		@Override
		protected String doInBackground(Void... params) {
			try {
				orderhistoryModel = ProviderFactory
						.createOrderServiceProvider().GetOrderStatusHistory(
								orderNumber,ActivityUtil.getCustomerToken(),ActivityUtil.getCustomerID());
			} catch (DxException e) {
				return e.getErrCode();
			} catch (Exception e) {
				Logger.e(TAG, "OrderHistoryAsyncTask", e);
			}
			return "0";
		}

		@Override
		protected void onPostExecute(String result) {
			// hideWaitingDialog();
//			hideWaitingDialog();
			super.onPostExecute(result);
			if ("0".equals(result)) {
				refreshHistory = false;
				setHistory();
			} else if(!isRelogin){
				// 提示信息
				AlertToast.alert(OrderDetailActivity.this,
						ServerConstant.ReturnCode.MESSAGEMAP.get(result));
			}
		}

		@Override
		protected Context setContext() {
			return OrderDetailActivity.this;
		}

		@Override
		protected BaseNeedReLoginTask setTask() {
			return new OrderHistoryAsyncTask();
		}
	}

	/**
	 * 为EditionOrder加锁
	 * 
	 * @author qsc255
	 * @version [版本号, 2015-2-3]
	 * @see [相关类/方法]
	 * @since [产品/模块版本]
	 */
	protected class BeginEditOrderAsyncTask extends
		BaseNeedReLoginTask {
		@Override
		protected void onPreExecute() {
			// showWaitingDialog();
			showLoadingLayout(null);
			// editorder.setEnabled(false);
		}

		@Override
		protected String doInBackground(Void... params) {
			try {
				// 为订单加锁
				ProviderFactory.createOrderServiceProvider().beginEditOrder(
						orderNumber, "", "",ActivityUtil.getCustomerToken(),ActivityUtil.getCustomerID());
			} catch (DxException e) {
				return e.getErrCode();
			} catch (Exception e) {
				Logger.e(TAG, "BeginEditOrderAsyncTask", e);
			}
			// 在解析接口返回数据是对对status值进行匹配 并以e.ErrCode在DXException中抛出
			return "0";
		}

		@Override
		protected void onPostExecute(String result) {
			if (!isFinishing()) {
//				hideWaitingDialog();
				hideAllLayout(scrollview);
				// editorder.setEnabled(true);
				if ("0".equals(result)) {
					Bundle bundle = new Bundle();
					bundle.putSerializable("orderModel", orderModel);
					bundle.putSerializable("countryModel", countryModel);
					bundle.putString("shippingMethod", order_shipping_method
							.getText().toString());
					Intent intent = new Intent(OrderDetailActivity.this,
							EditOrderActivity.class);
					intent.putExtras(bundle);
					OrderDetailActivity.this.startActivityForResult(intent,
							ServerConstant.Parameter.EDIT_REQUESTCODE);
				} else if(!isRelogin){
					if (null == ServerConstant.ReturnCode.MESSAGEMAP
							.get(result)) {
						AlertToast.alert(OrderDetailActivity.this,
								"Order could not be edited.");
					} else {
						AlertToast.alert(OrderDetailActivity.this,
								ServerConstant.ReturnCode.MESSAGEMAP
										.get(result));
					}
				}
			}
			//
		}

		@Override
		protected Context setContext() {
			return OrderDetailActivity.this;
		}

		@Override
		protected BaseNeedReLoginTask setTask() {
			return new BeginEditOrderAsyncTask();
		}

	}

	/**
	 * 确认收货
	 * 
	 * @author qsc255
	 * @version [版本号, 2015-3-6]
	 * @see [相关类/方法]
	 * @since [产品/模块版本]
	 */
	protected class ConfirmReceptAsyncTask extends
		BaseNeedReLoginTask {

		@Override
		protected void onPreExecute() {
//			showWaitingDialog();
			showLoadingLayout(null);
			oprationOrder.setEnabled(false);
		}

		@Override
		protected String doInBackground(Void... params) {
			try {
				userName = GlobalConfig.getInstance().getUserSessionCfg()
						.getUsername();
				// 收到货后完成订单
				ProviderFactory.createOrderServiceProvider().CompleteOrder(
						orderNumber, new Operator(userName, "Customer"),
						userName,ActivityUtil.getCustomerToken(),ActivityUtil.getCustomerID());
			} catch (DxException e) {
				e.getErrCode();
			} catch (Exception e) {
				Logger.e(TAG, "ConfirmReceptAsyncTask", e);
			}
			return "0";
		}

		@Override
		protected void onPostExecute(String result) {
			oprationOrder.setEnabled(true);
			if ("0".equals(result)) {
				oprationOrder.setVisibility(View.GONE);
				refreshAll = true;
				updateOrder();
				Intent intent = new Intent();
				intent.putExtra("type", 2);
				OrderDetailActivity.this.setResult(
						ServerConstant.Parameter.ORDER_DETAILS_REQUESTCODE,
						intent);
			} else if(!isRelogin){
//				hideWaitingDialog();
				hideAllLayout(scrollview);
				AlertToast.alert(OrderDetailActivity.this,
						ServerConstant.ReturnCode.MESSAGEMAP.get(result));
			}
		}

		@Override
		protected Context setContext() {
			return OrderDetailActivity.this;
		}

		@Override
		protected BaseNeedReLoginTask setTask() {
			return new ConfirmReceptAsyncTask();
		}
	}

	/**
	 * 将得到的订单详情信息放置到页面
	 * 
	 * @see [类、类#方法、类#成员]
	 */
	public void setData() {
		String moneyType = orderModel.getCurrencyCodeStr();
		// List<Liness> products=new ArrayList<Liness>();
		products.clear();
		List<Liness> lines = orderModel.getLines();
		if (null != lines && lines.size() > 0) {
			products.addAll(lines);
		}
		List<Liness> giftLines = orderModel.getGiftLines();
		if (null != giftLines && giftLines.size() > 0) {
			products.addAll(giftLines);
		}
		orderProductAdapter = new OrderProductAdapter(OrderDetailActivity.this,
				products, moneyType);
		order_detail_listview.setAdapter(orderProductAdapter);
		// 获取订单号
		order_on_number.setText(orderNumber);
		String firstName = orderModel.getShippingAddress().getFirstName();
		if (null != firstName && !"".equals(firstName)
				&& Character.isLowerCase(firstName.charAt(0))) {
			StringBuffer buffer = new StringBuffer();
			buffer.append(String.valueOf(firstName.charAt(0)).toUpperCase())
					.append(firstName.substring(1).toLowerCase());
			firstName = buffer.toString();
		}

		order_shipping_recipient.setText(firstName
				+ orderModel.getShippingAddress().getLastName());
		if (null == orderModel.getShippingAddress().getCountry()) {

			order_shipping_country.setText("");
		} else {
			order_shipping_country.setText((CharSequence) countryModel
					.getAllCountry().get(
							orderModel.getShippingAddress().getCountry()));
		}
		order_shipping_city.setText(orderModel.getShippingAddress().getCity());
		String street2 = orderModel.getShippingAddress().getStreet2();
		if (null == street2 || "".equals(street2)) {
			order_shipping_address.setText(orderModel.getShippingAddress()
					.getStreet1());

		} else {
			order_shipping_address.setText(orderModel.getShippingAddress()
					.getStreet1() + "," + street2);
		}
		order_shipping_code.setText(orderModel.getShippingAddress()
				.getPostalCode());
		order_shipping_tel.setText(orderModel.getShippingAddress()
				.getPhoneNumber());
		// order_shipping_method.setText(mapShippMethod.get(orderModel
		// .getShippingMethod()));
		String shipMethod = orderModel.getShippingMethod();
		if ("0".equals(shipMethod)) {
			order_shipping_method.setText("SuperSaver");
		} else if ("1".equals(shipMethod)) {
			order_shipping_method.setText("Standard");
		} else if ("2".equals(shipMethod)) {
			order_shipping_method.setText("Expedited");
		}
		double discount = orderModel.getAllDiscountTotal();
		if (discount > 0) {
			orderDiscountTotal.setVisibility(View.VISIBLE);
			orderDiscount.setVisibility(View.VISIBLE);
			orderDiscountTotal.setText("-" + moneyType
					+ String.format("%.2f", discount));
		} else {
			orderDiscountTotal.setVisibility(View.GONE);
			orderDiscount.setVisibility(View.GONE);
		}
		grandTotal.setText(moneyType
				+ String.format("%.2f", orderModel.getGrandTotal()));
		double dueAmount = orderModel.getDueAmount();
		if (dueAmount == orderModel.getGrandTotal() || dueAmount == 0) {
			dueAmountTotal.setVisibility(View.GONE);
			dueAmountTotalTV.setVisibility(View.GONE);
		} else {
			dueAmountTotal.setVisibility(View.VISIBLE);
			dueAmountTotalTV.setVisibility(View.VISIBLE);
			dueAmountTotal
					.setText(moneyType + String.format("%.2f", dueAmount));
		}
		shipping_total.setText(moneyType
				+ String.format("%.2f", orderModel.getReceivableShippingFee()));
		double shippingFeeDiscount = orderModel.getShippingFeeDiscount();
		if (shippingFeeDiscount > 0) {
			shipping_discount_total
					.setText("-"
							+ moneyType
							+ String.format("%.2f",
									orderModel.getShippingFeeDiscount()));
			shipping_discount_total.setVisibility(View.VISIBLE);
			shipping_discount.setVisibility(View.VISIBLE);
		} else {
			shipping_discount_total.setVisibility(View.GONE);
			shipping_discount.setVisibility(View.GONE);
		}
		/**
		 * 根据订单的不同状态改变订单标志图颜色及状态颜色、显示不同button
		 */
		final int orderLight = Integer.parseInt(orderModel.getLight());

		// uporDwon.setOnCheckedChangeListener(new OnCheckedChangeListener() {
		//
		// @Override
		// public void onCheckedChanged(CompoundButton buttonView,
		// boolean isChecked) {
		// if (isChecked) {
		// findViewById(R.id.order_rl_status02).setVisibility(
		// View.GONE);
		// findViewById(R.id.order_rl_status03).setVisibility(
		// View.GONE);
		// findViewById(R.id.order_rl_status04).setVisibility(
		// View.GONE);
		// if (orderLight != ServerConstant.MapKey.ORDER_CANCEL) {
		// order_detail_tracking01
		// .setImageResource(R.drawable.green);
		// } else {
		// order_detail_tracking01
		// .setImageResource(R.drawable.orange);
		// }
		// } else {
		// findViewById(R.id.order_rl_status02).setVisibility(
		// View.VISIBLE);
		// findViewById(R.id.order_rl_status03).setVisibility(
		// View.VISIBLE);
		// findViewById(R.id.order_rl_status04).setVisibility(
		// View.VISIBLE);
		// if (orderLight != ServerConstant.MapKey.ORDER_CANCEL) {
		// order_detail_tracking01
		// .setImageResource(R.drawable.top_green);
		// } else {
		// order_detail_tracking01
		// .setImageResource(R.drawable.top_orange);
		// }
		// }
		// }
		// });
		boolean canCancel = orderModel.isCanCancel();
		boolean canComplete = orderModel.isCanComplete();
		boolean canRePay = orderModel.isCanRepay();
		boolean isComplete = orderModel.isIsCompleted();
		boolean isCanceled = orderModel.isIsCancelled();
		if (canCancel) {
			rLayout.setVisibility(View.VISIBLE);
			cancelorder.setVisibility(View.VISIBLE);
			oprationOrder.setVisibility(View.GONE);
		} else {
//			rLayout.setVisibility(View.GONE);
			cancelorder.setVisibility(View.GONE);
		}
		if (canComplete) {
			rLayout.setVisibility(View.VISIBLE);
			cancelorder.setVisibility(View.GONE);
			oprationOrder.setVisibility(View.VISIBLE);
			// oprationOrder.setText(R.string.title_receipt_order);
			oprationOrder
					.setBackgroundResource(R.drawable.confirm_receipt_selector);
			isPay = false;
		}
		if (canRePay) {
			rLayout.setVisibility(View.VISIBLE);
			oprationOrder.setVisibility(View.VISIBLE);
			// oprationOrder.setText(R.string.title_pay_order);
			oprationOrder.setBackgroundResource(R.drawable.pay_selector);
			isPay = true;
		} else {
//			boolean IsPaymentCompleted = orderModel.isIsPaymentCompleted();
//			if (!IsPaymentCompleted) {
				rLayout.setVisibility(View.VISIBLE);
				oprationOrder.setVisibility(View.GONE);
//				// oprationOrder.setText(R.string.title_pay_order);
//				oprationOrder.setBackgroundResource(R.drawable.pay_selector);
//				isPay = true;
//			}
		}
//		if (isComplete || isCanceled) {
		if (isCanceled) {
			rLayout.setVisibility(View.GONE);
			orderStatus.setText(R.string.order_state_cancelled);
		}else{
			orderStatus.setText(orderModel.getOrderStatusStr());
		}

		// switch (orderLight) {
		// /**
		// * 未支付 orderLight =1 页面视图所对应的状态 Order Received
		// */
		// case ServerConstant.MapKey.ORDER_PENDING_PAYMENT:
		// case ServerConstant.MapKey.ORDER_PARTIAL_PAYMENT:
		// // order_detail_tracking01.setImageResource(R.drawable.top_green);
		// cancelorder.setVisibility(View.VISIBLE);
		// rLayout.setVisibility(View.VISIBLE);
		// oprationOrder.setVisibility(View.VISIBLE);
		// oprationOrder.setText(R.string.title_pay_order);
		// // tvOrderReceived.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvPaymentReceived.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// // tvFullShipment.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// // tvCompleted.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// if (orderLight == ServerConstant.MapKey.ORDER_PARTIAL_PAYMENT) {
		// orderStatus
		// .setText(ServerConstant.MapValue.ORDER_PARTIAL_PAYMENT);
		// // tvPaymentReceived
		// // .setText(ServerConstant.MapValue.ORDER_PARTIAL_PAYMENT);
		// // dueAmountTotal.setVisibility(View.GONE);
		// // dueAmountTotalTV.setVisibility(View.GONE);
		// } else {
		// orderStatus
		// .setText(ServerConstant.MapValue.ORDER_PENDING_PAYMENT);
		// // tvPaymentReceived.setText(R.string.details_payment_received);
		// // dueAmountTotal.setVisibility(View.VISIBLE);
		// // dueAmountTotalTV.setVisibility(View.VISIBLE);
		// }
		//
		// break;
		// /**
		// * 已支付 orderLight =2 页面视图所对应的状态 Payment Received
		// */
		// case ServerConstant.MapKey.ORDER_PAYMENT_RECEVIED:
		// // order_detail_tracking01.setImageResource(R.drawable.top_green);
		// // order_detail_tracking02.setImageResource(R.drawable.center_green);
		// rLayout.setVisibility(View.VISIBLE);
		// cancelorder.setVisibility(View.VISIBLE);
		// oprationOrder.setVisibility(View.GONE);
		// // tvOrderReceived.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvPaymentReceived.setText(R.string.details_payment_received);
		// // tvPaymentReceived.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvFullShipment.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// // tvCompleted.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// orderStatus.setText(ServerConstant.MapValue.ORDER_PAYMENT_RECEVIED);
		// break;
		// /**
		// * 发货 orderLight =3 页面视图所对应的状态 Full Shipment
		// */
		// case ServerConstant.MapKey.ORDER_FULL_SHIPMENT:
		// // order_detail_tracking01.setImageResource(R.drawable.top_green);
		// // order_detail_tracking02.setImageResource(R.drawable.center_green);
		// // order_detail_tracking03.setImageResource(R.drawable.center_green);
		// // tvPaymentReceived.setText(R.string.details_payment_received);
		// rLayout.setVisibility(View.VISIBLE);
		// cancelorder.setVisibility(View.GONE);
		// oprationOrder.setVisibility(View.VISIBLE);
		// oprationOrder.setText(R.string.title_receipt_order);
		// // cancelorder.setVisibility(View.GONE);
		// // editorder.setVisibility(View.GONE);
		// // tvOrderReceived.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvPaymentReceived.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvFullShipment.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvCompleted.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// orderStatus.setText(ServerConstant.MapValue.ORDER_FULL_SHIPMENT);
		// break;
		// /**
		// * 交易完成 orderLight =4 页面视图所对应的状态 Completed
		// */
		// case ServerConstant.MapKey.ORDER_COMPLETED:
		// // order_detail_tracking01.setImageResource(R.drawable.top_green);
		// // order_detail_tracking02.setImageResource(R.drawable.center_green);
		// // order_detail_tracking03.setImageResource(R.drawable.center_green);
		// // order_detail_tracking04.setImageResource(R.drawable.bottom_green);
		// // tvPaymentReceived.setText(R.string.details_payment_received);
		// rLayout.setVisibility(View.GONE);
		// viewline.setVisibility(View.GONE);
		// // editorder.setVisibility(View.VISIBLE);
		// // cancelorder.setVisibility(View.GONE);
		// // editorder.setVisibility(View.GONE);
		// // tvOrderReceived.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvPaymentReceived.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvFullShipment.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// // tvCompleted.setTextColor(getResources().getColor(
		// // R.color.order_green));
		// orderStatus.setText(ServerConstant.MapValue.ORDER_COMPLETED);
		// break;
		// /**
		// * 订单取消 orderLight =0 当订单状态为0是页面所有的状态标志与状态字体显示 orange
		// */
		// case ServerConstant.MapKey.ORDER_CANCEL:
		// //
		// order_detail_tracking.setImageResource(R.drawable.myorder_status_0);
		// rLayout.setVisibility(View.GONE);
		// // viewline.setVisibility(View.GONE);
		// // cancelorder.setVisibility(View.GONE);
		// // editorder.setVisibility(View.GONE);
		// // tvOrderReceived.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// // tvPaymentReceived.setText(R.string.details_payment_received);
		// // tvPaymentReceived.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// // tvFullShipment.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// // tvCompleted.setTextColor(getResources().getColor(
		// // R.color.order_orange));
		// orderStatus.setText(ServerConstant.MapValue.ORDER_CANCEL);
		// break;
		// default:
		// break;
		// }
		// String data = null == orderModel.getOrderDate() ? "" : orderModel
		// .getOrderDate().toString();
		// Date time = null;
		// try {
		// time = format1.parse(data);
		// } catch (ParseException e) {
		// // TODO Auto-generated catch block
		// }
		// String date = format.format(time);
		// order_detail_date_01.setText(date);
		
		//根据状态判断是否显示查看物流信息的按钮
		if("FullShipment".equals(orderModel.getOrderStatusStr())||"PartialShipment".equals(orderModel.getOrderStatusStr())
				|| "Completed".equals(orderModel.getOrderStatusStr())){
			checkShipping.setVisibility(View.VISIBLE);
		}else{
			checkShipping.setVisibility(View.GONE);
		}
//		if(orderModel.getPackages()!=null&&orderModel.getPackages().size()>0){
//			checkShipping.setVisibility(View.VISIBLE);
//		}else{
//			checkShipping.setVisibility(View.GONE);
//		}
		float sc = orderModel.getExpectReturnSCAmount();
		
		if(sc<=0f){
		    return ;
		}
		scdiv.setVisibility(View.VISIBLE);
		
		String boldString = orderModel.getCurrencyCodeStr()+sc;
		String scString = getString(R.string.sc_tip, boldString);
		
		int start = scString.lastIndexOf(boldString);
		int end = start + boldString.length();
		SpannableStringBuilder style = new SpannableStringBuilder(scString);
		style.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
		
		scTv.setText(style); 
		
	}

	/**
	 * 
	 * 订单历史记录
	 * 
	 * @return void [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 */
	void setHistory() {
		statusTrackingAdapter = new StatusTrackingAdapter(
				OrderDetailActivity.this, orderhistoryModel);
		order_tracking_listview.setAdapter(statusTrackingAdapter);
		/**
		 * 根据历史记录，显示不同的时间
		 */
		//
		// List<Date> orderPaymentTime = new ArrayList<Date>();
		// // DateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm");
		// for (int i = 0; i < orderhistoryModel.size(); i++) {
		// if (ServerConstant.MapKey.ORDER_PAYMENT_RECEVIED_STR
		// .equals(orderhistoryModel.get(i).getStatusCode())
		// || ServerConstant.MapKey.ORDER_PAYMENT_CONFIRMED_STR
		// .equals(orderhistoryModel.get(i).getStatusCode())
		// || ServerConstant.MapKey.ORDER_PARTIAL_PAYMENT_STR
		// .equals(orderhistoryModel.get(i).getStatusCode())) {
		//
		// try {
		// orderPaymentTime.add(format.parse(orderhistoryModel.get(i)
		// .getChangeOn()));
		// } catch (ParseException e) {
		// e.printStackTrace();
		// }
		//
		// }
		// if (ServerConstant.MapKey.ORDER_FULL_SHIPMENT_STR
		// .equals(orderhistoryModel.get(i).getStatusCode())) {
		// order_detail_date_03.setText(orderhistoryModel.get(i)
		// .getChangeOn());
		// }
		// if (ServerConstant.MapKey.ORDER_COMPLETED_STR
		// .equals(orderhistoryModel.get(i).getStatusCode())) {
		// order_detail_date_04.setText(orderhistoryModel.get(i)
		// .getChangeOn());
		// break;
		// }
		// }
		// // for (int i = 0; i < orderhistoryModel.size(); i++) {
		// // if (ServerConstant.MapKey.ORDER_COMPLETED_STR
		// // .equals(orderhistoryModel.get(i).getStatusCode())) {
		// // order_detail_date_04.setText(orderhistoryModel.get(i)
		// // .getChangeOn());
		// // break;
		// // }
		// // }
		// Collections.sort(orderPaymentTime);
		// if (orderPaymentTime.size() > 0) {
		//
		// order_detail_date_02.setText(format.format(orderPaymentTime
		// .get(orderPaymentTime.size() - 1)));
		// }
	}
	
	
	@Override
	protected View setLeftBtnContent(Boolean isBackIcon, int resId) {
		if ( ServerConstant.ActionConstant.ACTION_CHECKOUT.equals(fromActivity)) {
			if (!isBackIcon && -1 != resId) {
				return null;
			} else {
				topbarLeftTv.setVisibility(View.VISIBLE);
				topbarLeftTv.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						goToHome();
					}
				});
				if (isBackIcon) {
					topbarLeftTv.setCompoundDrawablesWithIntrinsicBounds(
							R.drawable.selector_topbar_back, 0, 0, 0);
				}
				if (-1 != resId) {
					topbarLeftTv.setText(resId);
				}
			}
			return topbarLeftTv;
		} else {
			return super.setLeftBtnContent(isBackIcon, resId);
		}

	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode==KeyEvent.KEYCODE_BACK){
			if(ServerConstant.ActionConstant.ACTION_CHECKOUT.equals(fromActivity)){
				goToHome();
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	
	private void goToHome(){
		Intent intent = new Intent();
		intent.setClass(this, HomeActivity.class);
		intent.putExtra(HomeActivity.CURRENT_TAB_TAG,
				getString(HomeActivity.titleArray[0]));
		startActivity(intent);
		finish();
	}
}
